package com.shop.controller;

import com.shop.domain.Contract;
import com.shop.service.ContractService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

import java.util.Date;

/**
 * ContractController
 * Created by heqianqian on 2017/7/12.
 */
@Controller
@RequestMapping("/cargo")
public class ContractController extends BaseController {

    @Resource
    private ContractService<Contract> contractService;

    /**
     * 合同左部列表
     */
    @RequestMapping("/left")
    public String left() {
        return "cargo/contract_left";
    }

    /**
     * 查看合同列表
     */
    @RequestMapping("/list")
    public String list(Model model) {
        List<Contract> contracts = contractService.find(null);
        model.addAttribute("datalist", contracts);
        return "cargo/contract_list";
    }

    /**
     * 跳转到添加页面
     */
    @RequestMapping("/create")
    public String create() {
        return "cargo/contract_create";
    }

    /**
     * 添加合同
     */
    @RequestMapping("/insert")
    public String insert(Contract contract) {
        contractService.insert(contract);
        return "redirect:/cargo/list";
    }

    /**
     * 跳转到修改合同页面
     */
    @RequestMapping("/modify")
    public String modify(@RequestParam("contractId") Long contractId, Model model) {
        Contract contract = contractService.get(contractId);
        model.addAttribute("obj", contract);
        return "cargo/contract_update";
    }

    /**
     * 修改合同
     */
    @RequestMapping("/update")
    public String update(Contract contract) {
        contractService.update(contract);
        return "redirect:/cargo/list";
    }

    /**
     * 查看合同详细信息
     */
    @RequestMapping("/detail")
    public String detail(@RequestParam("contractId") Long contractId, Model model) {
        Contract contract = contractService.get(contractId);
        model.addAttribute("obj", contract);
        return "/cargo/contract_view";
    }

    /**
     * 删除合同
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam("contractId") Serializable[] id) {
        contractService.delete(id);
        return "redirect:/cargo/list";
    }

    /**
     * 上报合同
     */
    @RequestMapping("/submit")
    public String submit(@RequestParam("contractId") Serializable[] id) {
        contractService.submit(id);
        return "redirect:/cargo/list";
    }

    /**
     * 取消合同
     */
    @RequestMapping("/cancel")
    public String cancel(@RequestParam("contractId") Serializable[] id) {
        contractService.cancel(id);
        return "redirect:/cargo/list";
    }
}
